// 评论集合规则

// 引入mongoose模块
const mongoose = require('mongoose');

// 创建规则
const commentSchema = new mongoose.Schema({
    // 评论内容
    content: {
        type: String,
        required: true,
        trim: true,
        minlength: 1
    },
    // 评论文章id
    articleId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Article', 
        required: true
    },
    // 评论人id
    userId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        required: true
    },
    // 评论时间
    publishDate: {
        type: Date,
        default: Date.now
    }
})

// 使用规则
let Comment = mongoose.model('Comment', commentSchema);

// 导出规则
module.exports = Comment;